package com.qf.domain;

import java.util.List;

/**
 *     分页实体类
 */
public class PageBean<T>{
    private int pageSize;//页的大小(每页显示的数据量)
    private int pageNum;//页码的总数
    private long totalSize;//总数量
    private int pageCount;//总页数
    private List<T> data;//分页中存储的数据量

    //后加
    private int startPage;//起始页
    private int endPage;//结束页

    public PageBean() {
    }

    public PageBean(int pageSize, int pageNum, long totalSize, List<T> data) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.totalSize = totalSize;
        this.data = data;
        //计算总页数
        this.pageCount=(int)(totalSize%pageSize==0?totalSize/pageSize:totalSize/pageSize+1);

        //计算动态页面
        //1正常情况 6~33
        this.startPage=this.pageNum-4;
        this.endPage=this.pageNum+5;
        //2查看页面小于5 1 2 3 4 5
        if(this.pageNum<=5){
            this.startPage=1;
            this.endPage=10;
        }
        //3查看页面大于等于pageCount-5  34~39
        if(this.pageNum>=this.pageCount-5){
            this.startPage=this.pageCount-9;//39-9=30
            this.endPage=this.pageCount;//39
        }
        //4不足10页
        if(this.pageCount<=10){
            this.startPage=1;
            this.endPage=this.pageCount;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageSize=" + pageSize +
                ", pageNum=" + pageNum +
                ", totalSize=" + totalSize +
                ", pageCount=" + pageCount +
                ", data=" + data +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                '}';
    }
}
